<?php
class form extends MySQL_Connector {

	public function __construct() {
		parent::__construct();
	}

	public function __destruct() {
	}

	public function set_attributes(Array $attrs) {
		$attribute = "";
		foreach ($attrs as $key => $value) {
			$attribute .= " ".$key."=\"" . $value . "\"";
		}
		return $attribute;
	}
	
	public function create_registration_form_in_table(Array $table_attributes, $form_action) {
		$attribute = $this->set_attributes($table_attributes);
		$method = new Method();
		echo $this -> get_form_start($form_action, $method -> post());
		echo "<table" . $attribute . ">";
		echo "<tr><td>Benutzername:</td><td>" . $this -> add_input("text", "bn", "") . "</td></tr>";
		echo "<tr><td>Passwort:</td><td>" . $this -> add_input("password", "pw", "") . "</td></tr>";
		echo "<tr><td>Passwort best&auml;tigen:</td><td>".$this->add_input("password", "enter_pw", "")."</td>";
		echo "<tr><td colspan=\"2\">" . $this -> add_input("submit", "register", "Registieren") . "</td></tr>";
		echo "</table>";
		echo $this -> get_form_end();
	}

	public function create_login_form_in_table(Array $table_attributes, $form_action) {
		$attribute = $this->set_attributes($table_attributes);
		$method = new Method();
		echo $this -> get_form_start($form_action, $method -> post());
		echo "<table" . $attribute . ">";
		echo "<tr><td>Benutzername:</td><td>" . $this -> add_input("text", "bn", "") . "</td></tr>";
		echo "<tr><td>Passwort:</td><td>" . $this -> add_input("password", "pw", "") . "</td></tr>";
		echo "<tr><td colspan=\"2\">" . $this -> add_input("submit", "login", "Einloggen") . "</td></tr>";
		echo "</table>";
		echo $this -> get_form_end();
	}

	public function create_login_form($form_action) {
		$method = new Method();
		echo $this -> get_form_start($form_action, $method -> post());
		echo "Benutzername: " . $this -> add_input("text", "bn", "") . "<br>";
		echo "Passwort: " . $this -> add_input("password", "pw", "") . "<br>";
		echo $this -> add_input("submit", "login", "Einloggen");
		echo $this -> get_form_end();
	}

	public function display_header($header_attrs, $str) {
		echo "<div".$this->set_attributes($header_attrs).">".$str."</div>";
	}
	
	public function get_drop_down(Array $options_name_value, $select_name) {
		$select = "<select name=\"".$select_name."\">";
		foreach($options_name_value as $key => $value) {
			$select .= "<option value=\"".$key."\">".$value."</option>";
		}
		$select .= "</select>";
		return $select();
	}

	public function add_input($type, $name, $value) {
		return "<input type=\"" . $type . "\" name=\"" . $name . "\" value=\"" . $value . "\" />";
	}

	public function get_form_start($action, Method $method) {
		return "<form action=\"" . $action . "\" method=\"" . $method . "\">";
	}

	public function get_form_end() {
		return "</form>";
	}

}
?>